﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ChangeProblem.Logic
{
    
   public class ChangeDemoSecond
    {
  

        /// <summary>
        /// Show your till payment
             /// </summary>
        public int[] ReturnCondition(decimal balance, int[] change,int[] cost, decimal[] currencies)
        {
               if (balance < 0)
                return null;
            for (int i = 0; i < cost.Length; i++)
                change[i] = cost[i] + change[i];
   
                            for (int i = 1; i < change.Length; i++)
                            {
                    
                                int count= (int)(balance / currencies[i]);
                                if (change[i] >= count) {

                                    change[i] = change[i] - count;
                                    balance = balance % currencies[i];

                                }
                                else
                                {

                                    change[i] = 0;
                                   balance = balance % currencies[i] + (count - change[i]) * currencies[i];
                                 }

                            }
            

            if (balance == 0)
                 return change;
            else 
                return null ; 
        }
    }
}
